home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 45
/
Amiga Format CD45 (1999-09)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-11].iso
/
-serious-
/
misc
/
football
/
exec
/
alt_league.rexx
next >
Wrap
OS/2 REXX Batch file
|
1999-08-16
|
18KB
|
509 lines
/* ***********************************************************************
ALTERNATIVE LEAGUE PROGRAM FOR FOOTBALL REXX SUITE
----------------------------------------------------
Copyright Mark Naughton 1996
Version Date History
--------------------------------------------------------------------------
1.0 090996 First release.
090996 As the sort doesnt flip the negative numbers, was
thought to be a problem, the league is checked and
flipped correctly (LEAGUE2.REXX)
120996 Amended same code as it didn't work if the two 'signs'
were different. Now flips them correctly.
(LEAGUE2.REXX)
180996 Changed record-count so that it is stored in element
zero of each array. Deleted some variable assigns
that weren't needed. Amended reading into arrays so
that the count is set correctly for one element.
Removed all "call "references before library routines.
180996 Removed all "call " references, used element zero to
store the record-count. (LEAGUE2.REXX)
260996 Amended program so that the sortprogram and the REXX
program to display the league are called from here
instead of a separate script file. Changed so that the
count is not stored in 'zero' element.
270996 Added code for points_per_draw and points_per_loss.
Updated to use new filenames. Improved error messages.
Inserted code from LEAGUE2.REXX to speed things up and
to tidy the code. Finally got the table to be sorted
properly, using a version of VSORTA from asd_library.
1.1 111196 Added argument so it can become a component of
FOOTBALL. Removed GAMEPLAY and EXTRACT. Removed all
messages.
131196 Added checks for files - if not found, exits without
a message.
141196 Added code to highlight the leader.
201196 Added code to sort out which teams are relegated and
then to display the line at the correct place.
211196 Updated and tidied the display.
231296 Shortened lines when displaying the league.
241296 Tidied up display again.
1.2 110497 Added code to support Points_Per_Goals. Amended the
table display.
070597 Amended code that checks league_file to see if they
are in the right order - was using wrong parameters.
080597 Amended as FOOTSORT is only used for league table file
sorting.
2.0 240997 Tidied up code and added errors in case any files cannot
be read or written to. Simplified reading of teams and
data (getting it from '.df' now, not '.stats') and
getting the total teams without having to re-read the
'.stats' file. Added promotion bar.
151297 Tidied display.
030599 Fixed bug in relegation bar - it would show it at the
maximum position for the number of teams relegated but
this wasn't true when a team was relegated and the
others still had to fight it out - same for the
promotion bar.
050599 Okay, I decided to change the display again.
2.1 150599 At request of Jan Andersen, I have modified League.rexx
to display home and away stats in the league table.
This can be used to replace the standard league program.
170599 Fixed bug in display of relegated teams as they all
showed in upper case when 2 hadn't had the misfortune.
Fixed bug reported by Kev (Thanks!) where Bolton from
the 97/98 English Premiership weren't upper-cased -
traced to the fact that they had the same points as
the place above - changed so calculation is changed if
its the last game of the season.
170699 Fixed bug where if all teams had zero points, the
promotion bar was still displayed.
**************************************************************************
Procedure
---------
1. Check files exist. Open 'Teams.df'.
2. Read in teams and their associated data; WIN, DRAW, LOST etc.
3. Close file. Open 'Teams.stats'. Read data. Close file.
4. Open 'Teams.sf' for reading.
5. Read each line that has a game played, and from that get the team names
and the score. Then update the relevant team data with the result.
6. Write data in form of a league table to an output file.
7. Close file.
8. Call external sortprogram to sort the output file.
9. Open 'Teams.stats' and read the number of teams, then close.
10.Open 'League.output' and read contents into two arrays.
11.Check to see if the teams are in the right order, comparing the points
of each one with the next and if the goal-differences are in the wrong
order, then swap the two teams.
12.Check to see which teams are relegated by calculating the maximum number
of points available and seeing if the lower teams are able to move up.
If not they are relegated, according to the number set.
13.Check to see which teams are promoted by using the same method as above.
14.Display league and exit.
************************************************************************** */
ARG league_file
version = 2
league_file = "Data/" || league_file
input_file = '.stats'
input2_file = '.sf'
input3_file = '.df'
output_file = 'Data/League.output'
title = '*LEAGUE_NAME='
points_win = '*POINTS_PER_WIN='
points_drw = '*POINTS_PER_DRW='
points_lse = '*POINTS_PER_LSE='
points_gls = '*POINTS_PER_GLS='
releg = '*RELEGATION='
playother = '*PLAY_OTHER='
promoted = '*PROMOTED='
team_counter = '*COUNTR='
team = '*TEAM='
played = '*PLY='
won = '*WIN='
drawn = '*DRW='
lost = '*LST='
goalsf = '*GOF='
goalsa = '*GOA='
points = '*PTS='
separator = '*'
teams. = '???'
teams2. = '???'
m_ply. = '???'
m_win. = '???'
m_drw. = '???'
m_lost. = '???'
m_gof. = '???'
m_goa. = '???'
m_pts. = '???'
h_ply. = '???'
h_win. = '???'
h_drw. = '???'
h_lost. = '???'
h_gof. = '???'
h_goa. = '???'
h_pts. = '???'
a_ply. = '???'
a_win. = '???'
a_drw. = '???'
a_lost. = '???'
a_gof. = '???'
a_goa. = '???'
a_pts. = '???'
ah_teams. = '???'
teams_ctr = 0
playo = 2
reg = 2
ptsgls = 0
ptswin = 2
ptsdrw = 1
ptslse = 0
promo = 0
not_played = '__ __'
if exists(league_file || input_file) = 0 then exit
if exists(league_file || input2_file) = 0 then exit
if exists(league_file || input3_file) = 0 then exit
tcount = 0
if open(datafile,league_file || input3_file,'r') then do
do while ~eof(datafile)
line = readln(datafile)
if pos(title,line) > 0 then league_title = delstr(line,1,13)
if pos(points_win,line) > 0 then ptswin=delstr(line,1,16)
if pos(points_drw,line) > 0 then ptsdrw=delstr(line,1,16)
if pos(points_lse,line) > 0 then ptslse=delstr(line,1,16)
if pos(points_gls,line) > 0 then ptsgls=delstr(line,1,16)
if pos(releg,line) > 0 then reg = delstr(line,1,12)
if pos(playother,line) > 0 then playo = delstr(line,1,12)
if pos(promoted,line) > 0 then promo = delstr(line,1,10)
if pos(separator,line) = 0 then do
line = strip(line)
tcount = tcount + 1
teams.tcount = line
ah_teams.tcount = line
end
end
close(datafile)
end
else do
say
say "ERROR : (League)"
say
say "Unable to open '"league_file || input3_file"' file."
exit
end
if open(datafile,league_file || input_file,'r') then do
do while ~eof(datafile)
line = readln(datafile)
if pos(team,line) > 0 then
teams_ctr = teams_ctr + 1
if pos(played,line) > 0 then m_ply.teams_ctr = delstr(line,1,5)
if pos(won,line) > 0 then m_won.teams_ctr = delstr(line,1,5)
if pos(drawn,line) > 0 then m_drw.teams_ctr = delstr(line,1,5)
if pos(lost,line) > 0 then m_lost.teams_ctr = delstr(line,1,5)
if pos(goalsf,line) > 0 then m_gof.teams_ctr = delstr(line,1,5)
if pos(goalsa,line) > 0 then m_goa.teams_ctr = delstr(line,1,5)
if pos(points,line) > 0 then m_pts.teams_ctr = delstr(line,1,5)
end
close(datafile)
end
else do
say
say "ERROR : (League)"
say
say "Unable to open '"league_file || input_file"'."
exit
end
ggg = 0
do i=1 to teams_ctr
if m_ply.i ~= 0 then ggg = 1
end
if ggg = 1 then do
do i=1 to teams_ctr
h_ply.i = m_ply.i
h_won.i = m_won.i
h_drw.i = m_drw.i
h_lost.i= m_lost.i
h_gof.i = m_gof.i
h_goa.i = m_goa.i
h_pts.i = m_pts.i
end
end
else do
do i=1 to teams_ctr
h_ply.i = 0
h_won.i = 0
h_drw.i = 0
h_lost.i= 0
h_gof.i = 0
h_goa.i = 0
h_pts.i = 0
a_ply.i = 0
a_won.i = 0
a_drw.i = 0
a_lost.i= 0
a_gof.i = 0
a_goa.i = 0
a_pts.i = 0
end
end
if open(datafile,league_file || input2_file,'r') then do
do while ~eof(datafile)
line = readln(datafile)
if pos(separator,line) = 0 then do
if pos(not_played,line) = 0 then do
home_team = strip(substr(line,1,30))
goals_for = substr(line,32,2)
goals_aga = substr(line,37,2)
away_team = strip(substr(line,41,30))
do i=1 to teams_ctr
if home_team = teams.i then do
m_ply.i = m_ply.i + 1
m_gof.i = m_gof.i + goals_for
m_goa.i = m_goa.i + goals_aga
h_ply.i = h_ply.i + 1
h_gof.i = h_gof.i + goals_for
h_goa.i = h_goa.i + goals_aga
if goals_for = goals_aga then do
m_drw.i = m_drw.i + 1
m_pts.i = m_pts.i + ptsdrw
h_drw.i = h_drw.i + 1
h_pts.i = h_pts.i + ptsdrw
end
if goals_for < goals_aga then do
m_lost.i= m_lost.i + 1
m_pts.i = m_pts.i + ptslse
h_lost.i= h_lost.i + 1
h_pts.i = h_pts.i + ptslse
end
if goals_for > goals_aga then do
m_won.i = m_won.i + 1
m_pts.i = m_pts.i + ptswin
h_won.i = h_won.i + 1
h_pts.i = h_pts.i + ptswin
end
m_pts.i = m_pts.i + (goals_for * ptsgls)
end
end
do i=1 to teams_ctr
if away_team = teams.i then do
m_ply.i = m_ply.i + 1
m_gof.i = m_gof.i + goals_aga
m_goa.i = m_goa.i + goals_for
a_ply.i = a_ply.i + 1
a_gof.i = a_gof.i + goals_aga
a_goa.i = a_goa.i + goals_for
if goals_for = goals_aga then do
m_drw.i = m_drw.i + 1
m_pts.i = m_pts.i + ptsdrw
a_drw.i = a_drw.i + 1
a_pts.i = a_pts.i + ptsdrw
end
if goals_for < goals_aga then do
m_won.i = m_won.i + 1
m_pts.i = m_pts.i + ptswin
a_won.i = a_won.i + 1
a_pts.i = a_pts.i + ptswin
end
if goals_for > goals_aga then do
m_lost.i= m_lost.i + 1
m_pts.i = m_pts.i + ptslse
a_lost.i= a_lost.i + 1
a_pts.i = a_pts.i + ptslse
end
m_pts.i = m_pts.i + (goals_aga * ptsgls)
end
end
end
end
end
close(datafile)
end
else do
say
say "ERROR : (League)"
say
say "Unable to open '"league_file || input2_file"'."
exit
end
if open(outfile,output_file,"w") then do
do i=1 to teams_ctr
line = left(teams.i,30,' ')
mp = right(m_ply.i,3)
mw = right(m_won.i,3)
md = right(m_drw.i,3)
ml = right(m_lost.i,3)
mgf = right(m_gof.i,5)
mga = right(m_goa.i,5)
mpts = right(m_pts.i,7)
writech(outfile,line" "mp" "mw" "md" "ml" "mgf" "mga" "mpts" ")
itemp=mgf-mga
if itemp>0 then
itemp=insert("+",itemp,0,1)
itemp=right(itemp,4)
writeln(outfile,itemp)
end
close(outfile)
end
else do
say
say "ERROR : (League)"
say
say "Unable to update the League. Cannot write to '"output_file"'."
exit
end
address command 'Exec/footsort '
if open(datafile2,output_file,'r') then do
do i=1 to tcount
line = readln(datafile2)
teams.i = line
teams2.i = line
end
close(datafile2)
end
else do
say
say "ERROR : (League)"
say
say "Cannot read '"output_file"'."
exit
end
ctr = 0
do while swapctr > 0
swapctr=9
do i=1 to tcount-1 /* was 64,4 and 77,4 */
swapdone=0
j = i + 1
if strip(substr(teams.i,64,7)) = strip(substr(teams.j,64,7)) then do
goaldiffa = strip(substr(teams.i,77,5))
goaldiffb = strip(substr(teams.j,77,5))
if goaldiffa < goaldiffb then do
teams.i = teams2.j
teams.j = teams2.i
teams2.i= teams.i
teams2.j= teams.j
swapdone= 1
ctr = ctr + 1
end
end
if swapdone = 1 then
break
end
if ctr = 0 then
swapctr = 0
else
ctr = 0
end
posreg = 0
pospro = 0
if reg > 0 then do /* this bit of code checks to see which teams are relegated */
wherereg = tcount - reg
regpts = strip(substr(teams.wherereg,64,7)) /* was 64,4 */
do i=tcount to 1 by -1
b = (((tcount-1) * playo) - strip(substr(teams.i,35,3))) * ptswin /* was 36,2 */
c = strip(substr(teams.i,64,7)) + b
if c < regpts then posreg = i /* calculates the max points avail */
if c = regpts & strip(substr(teams.i,35,3)) = ((tcount-1) * playo) then
posreg = i
end
if posreg < (wherereg+1) & posreg ~= 0 then /* was 0 - set to reqd pos if higher */
posreg = wherereg + 1
/* Bug fix 0305 - relegation bar problems */
end
/* ---------------------------------------------- */
if promo > 0 then do /* this bit of code checks to see which teams are promoted */
wherepro = promo + 1
propts = strip(substr(teams.wherepro,64,7)) /* was 64,4 */
do i=1 to tcount
if strip(substr(teams.i,35,3)) > 0 then
b = (((tcount-1) * playo) - strip(substr(teams.i,35,3))) * ptswin
else
b = 0
c = strip(substr(teams.i,64,7)) + b
if c > propts then pospro = i /* calculates the max points avail */
end
if pospro > (wherepro-1) & pospro ~= 0 then
pospro = wherepro - 1 /* was 0 - set to reqd pos if lower */
end
/* ---------------------------------------------- */
lengtt = 0
do i=1 to tcount
if length(ah_teams.i) > lengtt then
lengtt = length(ah_teams.i)
end
if lengtt > 30 then
lengtt = 30
tabtitle = " Pl Won Drw Lst GF GA "left(" ",lengtt+3,' ')" Pl Won Drw Lst GF GA Pts GD"
tabunder = left("-",length(tabtitle)+4,'-')
say
say center(league_title,88)
say tabunder
say
if ggg = 1 then do
say "This league does not contain all the scores as it was started mid-way. Therefore the"
say "data has been recorded under HOME."
end
say
say " Home Pos. "left("Team",lengtt+3,' ')" Away"
say
say tabtitle
say tabunder
say
do i=1 to tcount
team1 = strip(substr(teams.i,1,30))
do j=1 to tcount
if pos(team1,ah_teams.j) > 0 then do
h1 = right(h_ply.j,4,' ')
h2 = right(h_won.j,4,' ')
h3 = right(h_drw.j,4,' ')
h4 = right(h_lost.j,4,' ')
h5 = right(h_gof.j,6,' ')
h6 = right(h_goa.j,6,' ')
a1 = right(a_ply.j,4,' ')
a2 = right(a_won.j,4,' ')
a3 = right(a_drw.j,4,' ')
a4 = right(a_lost.j,4,' ')
a5 = right(a_gof.j,6,' ')
a6 = right(a_goa.j,6,' ')
gdif = substr(teams.i,76,5)
if strip(gdif) = 0 then
gdif = " "
rocky = h1||h2||h3||h4||h5||h6||" ("right(i,2,' ')") "left(ah_teams.j,lengtt+3)||a1||a2||a3||a4||a5||a6" "right(strip(substr(teams.i,64,7)),7,' ')" "gdif
end
end
if i >= posreg & posreg~=0 then rocky = upper(rocky)
if i = 1 then rocky = upper(rocky)
say rocky
if i = (tcount-reg) & reg > 0 & posreg~=0 then do /* was posreg */
say left("_",length(tabunder),'_')
say
end
if i = (promo) & promo > 0 & pospro~=0 then do /* was pospro */
say left("_",length(tabunder),'_')
say
end
end
say
say tabunder
say
exit